import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class code3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int v = in.nextInt();
        int n = in.nextInt();
        int[] arr = new int[n+1];
        for(int i=1;i<n+1;i++) {
            arr[i] = in.nextInt();
        }
        int[][] dp = new int[n+1][v+1];//前i个物品中，总体积不超过j
        for(int i=1;i<=n;i++) {
            for(int j=0;j<=v;j++) {
                dp[i][j] = dp[i-1][j];
                if(j>=arr[i]) {
                    dp[i][j] = Math.max(dp[i][j],dp[i-1][j-arr[i]]+arr[i]);
                }
            }
        }
        System.out.print(v-dp[n][v]);

    }
}